package com.huisou.indexhelp;

import java.util.Iterator;
import java.util.Map.Entry;
import java.util.Set;

import org.apache.solr.client.solrj.SolrServer;
import org.apache.solr.client.solrj.response.UpdateResponse;
import org.apache.solr.common.SolrInputDocument;
import org.apache.solr.common.SolrInputField;

import com.huisou.solrj.SolrServerUtil;

public class InsertIndex {
	
	public static void main(String[] args) throws Exception {
		String solrcore = "company";
		SolrServer server = SolrServerUtil.getSolrServer(solrcore);
		SolrInputDocument doc = new SolrInputDocument();
		
		doc.addField("id", "6025720");
		doc.addField("name", "北京友联亚泰机械制造有限责任公司");
		doc.addField("title", "北京友联亚泰机械制造有限责任公司");
		doc.addField("domain", "bjylyt");
		doc.addField("avatar", "http://img.e.huisou.com/upload/2012/07/07/6025720_middle_logo.jpg");
		doc.addField("summary", "北京友联亚泰机械制造有限公司，是科集、工、贸为一体的综合性实业性公司，主要研制制冷设备、烧烤设备、食品机械！如冰淇淋机、冷热饮机、刨冰机、炒冰机、炒货机、粉丝机、烤鸭炉、烤鸡炉、无烟烧烤机、豆腐豆浆机、玉米爆花机等产品。本公司立足于北京，面向全国世界致力于品牌建设和企业可持续发展、我们竭诚欢迎全国各地客商光临指导，洽谈业务。建立友好合作关系，共同创美好明天。");
		doc.addField("address", "北京市大兴区");
		doc.addField("etypeId", "114");
		doc.addField("etype", "有限责任公司");
		doc.addField("cateCode", "017079");
		doc.addField("professionId", "456");
		doc.addField("profession", "制冷设备");
		doc.addField("opmodeId", "7");
		doc.addField("opmode", "生产加工");
		doc.addField("business", "冰淇淋机 冷热饮机 刨冰机 炒冰机 烤禽箱 粉丝机 玉米爆花机 土耳其烤肉机 豆腐豆浆机");
		doc.addField("countryId", "1");
		doc.addField("country", "中国");
		doc.addField("stateId", "2");
		doc.addField("state", "北京市");
		doc.addField("cityId", "3");
		doc.addField("city", "北京市");
		doc.addField("status", "1");
		doc.addField("pid", "13");
		doc.addField("pCode", "017");
		doc.addField("pname", "机械及行业设备");		
		doc.addField("grade", "2");
		doc.addField("totalPoint", "1116");
		doc.addField("fineFlg", "1");

		server.add(doc);		
		server.commit();
	}
	
	public static String toXML(SolrInputDocument doc) {
		Set<Entry<String, SolrInputField>> set = doc.entrySet();
		Iterator<Entry<String, SolrInputField>> it = set.iterator();
		StringBuilder ret = new StringBuilder("<add><doc>");
		while (it.hasNext()) {
			Entry<String, SolrInputField> en = it.next();
			String key = en.getKey();
			String val = (String) en.getValue().getValue();
			ret.append("<field name=\"").append(key).append("\">").append(val).append("</field>");
		}
		ret.append("</doc></add>");
		return ret.toString();
	}
}
